package com.taptech.doufu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.taptech.doufu.R;

public class TTShareAdapter extends BaseAdapter {
	/** 新浪微博 */
	public final static int SHARE_TO_SINA_WEIBO = 0;
	/** 微信 */
	public final static int SHARE_TO_WEIXIN = 1;
	/** 微信朋友圈 */
	public final static int SHARE_TO_PENGYOUQUAN = 2;
	/** 短信 */
	public final static int SHARE_TO_MESSAGE = 3;
	/** 邮件 */
	public final static int SHARE_TO_EMAIL = 10;

	/** QQ */
	public final static int SHARE_TO_TECENT_QQ = 4;
	/** QQ空间 */
	public final static int SHARE_TO_TECENT_SPACE = 5;
	public final static int COPY_THE_SHARE_LINK = 6;
	public final static int SHARE_TO_SYSTEM_MORE = 7;
	private int type;
	/*
	 * public final static SHARE_MEDIA[] ALL_SHARE_MEDIAS = { SHARE_MEDIA.SINA,
	 * SHARE_MEDIA.TENCENT, SHARE_MEDIA.TENCENT };
	 */

	private int[] mIconResId = { R.drawable.invite_sina,
			R.drawable.invite_weixin, R.drawable.invite_friends,
			R.drawable.icon_share_message,
			 R.drawable.invite_qq,
			R.drawable.invite_qzone,
			R.drawable.copy_share_link_icon,
			R.drawable.invite_system_more };

	private int[] mTitleResId = { R.string.common_share_title_sinaweibo,
			R.string.common_share_title_weixin,
			R.string.common_share_title_pengyouquan,
			R.string.common_share_title_message,
			R.string.common_share_title_qq,
			R.string.common_share_title_qq_space,
			R.string.common_copy_share_link,
			R.string.common_share_title_more,

	};

	private Context mContext;
	private boolean shareTopFlag;

	public TTShareAdapter(Context context) {
		this.mContext = context;
	}

	public TTShareAdapter(Context context, int type) {
		this.type = type;
		this.mContext = context;
	}

	public void setShartTopFlag(boolean shareTopFlag) {
		this.shareTopFlag = shareTopFlag;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return type == 1 ? 5 : mIconResId.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		ViewHolder holder = null;

		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.reader_share_item, null);
			holder = new ViewHolder();
			holder.icon = (ImageView) convertView
					.findViewById(R.id.iv_reader_share_icon);
			if (shareTopFlag) {
				int sizeSpace = (int) mContext.getResources().getDimension(
						R.dimen.share_top_icon_size);
				RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
						sizeSpace, sizeSpace);
				lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
				lp.setMargins(
						0,
						(int) mContext.getResources().getDimension(
								R.dimen.share_top_icon_size_top), 0, 0);
				holder.icon.setLayoutParams(lp);
			}
			holder.title = (TextView) convertView
					.findViewById(R.id.tv_reader_share_title);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.icon.setImageResource(mIconResId[position]);
		holder.title.setText(mTitleResId[position]);

		return convertView;
	}

	class ViewHolder {
		ImageView icon;
		TextView title;
	}

}
